// add this file to the module.js
angular.module('wechat').controller('keywordSelectedContentCtrl', ['$scope', 'Pagination', 'wechatService', function ($scope, Pagination, wechatService) {

    var pagination = $scope.pagination = Pagination.create({
        itemsPerPage: window.user.perPage,
        maxNumbers: 5,
        itemsCount: 0
    });

    pagination.onChange = function (page) {
        onLoadData({page: page});
    };
    $scope.datas = [];

    function onLoadData(params) {
        var searchParams = _.assign({
            'page': 0,
            'perPage': pagination.itemsPerPage
        }, params);

        wechatService.contentList(searchParams).then(function (response) {
            pagination.itemsCount = response.total;
            $scope.datas = response.result;
        }, function (error) {
            layui.use('layer', function () {
                layer.alert(error, {icon: 2}, function (index) {
                    layer.close(index);
                });
            });
        })
    }

    onLoadData();

    $scope.selected = function (x) {
        xlayer.close(_.pick(x, ['id', 'title']));
    }
}]);